
/* 
 * Copyright (c)	Insighten Intelligent Equipment co.,LTD
 * 
 *  Use of this software is controlled by the terms and conditions found
 *  in the license agreement under which this software has been supplied.
 * 
 */
/** 
 * @file msg_svr_main.c
 * @brief test message library functions
 * @author taco [tacoee@gmail.com]
 * @version 0.1
 * @date 2010-09-13
 */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>

#include "types.h"
#include "message.h"
#include "msg.h"

int main(int argc, char *argv[])
{
	Message *msg = NULL;
	MsgContex *mcp = NULL;
	int i=0;

	msg = msg_create(MSG_KEY, sizeof(MsgContex));

	if (msg != NULL) {
		mcp = (MsgContex *)msg->msg_t;
	}

	while(i < 10) {
		mcp->des = MSG_TYPE_SVR;
		mcp->src = MSG_TYPE_CLI;
		mcp->m_len = snprintf(mcp->m, 1024,"%d Send message to server.\n", i++);
		if (msg_send(msg) < 0) {
			perror("Send.");
			break;
		}
		if (msg_rcv(msg, MSG_TYPE_CLI) < 0) {
			perror("Rcevice.");
			break;
		} else {
			fprintf(stdout,"%s\n", mcp->m); 
		}
	}
	msg_destory(msg);
	return 0;
}
